package org.adream.account.restful;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.adream.account.entity.AreaEntity;
import org.adream.account.entity.DonornDreamCenterLinkEntity;
import org.adream.account.entity.DonornEntity;
import org.adream.account.entity.Dream2020DonornDreamCenterLinkEntity;
import org.adream.account.entity.Dream2020DonornEntity;
import org.adream.account.entity.Dream2020DreamCenterEntity;
import org.adream.account.entity.Dream2020FeedEntity;
import org.adream.account.entity.Dream2020SchoolEntity;
import org.adream.account.entity.DreamCenterEntity;
import org.adream.account.entity.RealNameAuthEntity;
import org.adream.account.entity.RoleEntity;
import org.adream.account.entity.SchoolEntity;
import org.adream.account.entity.TagEntity;
import org.adream.account.entity.UserAddressEntity;
import org.adream.account.entity.UserDetailEntity;
import org.adream.account.entity.UserEntity;
import org.adream.account.entity.UserVerifyEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.model.UserRoleResModel;
import org.adream.account.restful.vo.BankVO;
import org.adream.account.restful.vo.SchoolVO;
import org.adream.account.restful.vo.UserVO;
import org.adream.account.service.ADreamServiceException;
import org.adream.account.service.AreaService;
import org.adream.account.service.BasicInfoService;
import org.adream.account.service.DonornService;
import org.adream.account.service.Dream2020DonornService;
import org.adream.account.service.Dream2020DreamCenterService;
import org.adream.account.service.Dream2020FeedService;
import org.adream.account.service.Dream2020SchoolService;
import org.adream.account.service.Dream2020UserService;
import org.adream.account.service.DreamCenterService;
import org.adream.account.service.LogRestfulService;
import org.adream.account.service.LoginService;
import org.adream.account.service.RealNameAuthService;
import org.adream.account.service.RoleService;
import org.adream.account.service.SchoolBasicInfoService;
import org.adream.account.service.SchoolService;
import org.adream.account.service.UserAddressService;
import org.adream.account.service.UserDetailService;
import org.adream.account.service.UserService;
import org.adream.account.service.UserVerifyService;
import org.adream.account.service.async.AsyncService;
import org.adream.account.service.async.LogRestfulEntity;
import org.adream.account.service.ws.SynDataEntity;
import org.adream.account.service.ws.SynDataService;
import org.adream.account.service.ws.WebServiceResponse;
import org.adream.account.util.ChineseCharToEnUtil;
import org.adream.account.util.Constant;
import org.adream.account.util.DateUtils;
import org.adream.account.util.IdGenerator;
import org.adream.account.util.RSACoderUtil;
import org.adream.account.util.SDKTestSendTemplateSMS;
import org.adream.account.util.UserUtil;
import org.adream.account.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;

/**
 * 第三方调用接口
 * 
 * @author wb
 *
 */
@Controller
@RequestMapping(value = "/restful/")
public class UserRestController {

	private final static Logger logger = LoggerFactory.getLogger(UserRestController.class);

	@Autowired
	private UserService userService;
	
	@Autowired
	private SchoolService schoolService;
	
	@Autowired
	private LoginService loginService;

	@Autowired
	private BasicInfoService basicInfoService;
	
	@Autowired
	private SynDataService synDataService;
	
	@Autowired
	private UserVerifyService verifyService;
	
	@Autowired
	private RoleService roleService;
	
	@Value("${headimgurl.prefix}")
	private String headimgurlPrefix; // 图片地址前缀
	
	@Value("${image.file.path.verifypic}")
	private String verifyPicPath; // 认证图片
	
	@Autowired
	private AsyncService asyncService;
	
	@Autowired
	private LogRestfulService logRestfulService;
	
	@Autowired
	private UserDetailService userDetailService;
	
	@Autowired
	private UserAddressService userAddressService;

	@Autowired
	private AreaService areaService;
	
	@Autowired
	private Dream2020SchoolService dream2020SchoolService;
	
	@Autowired
	private RealNameAuthService realNameAuthService;
	
	@Autowired
	private DonornService donornService;
	
	@Autowired
	private Dream2020DonornService dream2020DonornService;
	
	@Autowired
	private DreamCenterService dreamCenterService;
	
	@Autowired
	private Dream2020DreamCenterService dream2020DreamCenterService;
	
	@Autowired
	private Dream2020UserService dream2020UserService;
	
	@Autowired
	private SchoolBasicInfoService schoolBasicInfoService;
	
	@Autowired
	private Dream2020FeedService dream2020FeedService;
	
	/**
	 *  对象字段  null
	 *  	String 转 空字符串
	 *  	Integer 类型 转 0 
	 *  
	 *  	注意： 若有其他特殊类型转换错误， 再特殊处理
	 * @param t
	 * @return
	 * @throws Exception
	 */
	private <T> T handleData(T t) throws Exception{
        Field[] fields = t.getClass().getDeclaredFields(); 
        for(int i=0; i<fields.length; i++){  
            Field f = fields[i];  
            f.setAccessible(true);  
            if(f.get(t) == null) {
            	Class<?> type = f.getType();
            	if(type == int.class || type == Integer.class ) {
            		 f.set(t,0);
            	} else {
            		 f.set(t,"");
            	}
           	
            }
            f.setAccessible(false);
        }  
        return t;
	}

	/**
	 * 1通过uid查询用户
	 * 
	 * @param uid
	 *            用户id
	 * @return
	 */
	@RequestMapping(value = "queryUserByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserByUid(String uid,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数为空", null);
		}
		UserEntity userEntity = userService.queryUserByUid(uid);
		if(userEntity==null) {
			return new ResultModel<String>(ResultModel.ERR_DATABASE, "获取失败,对应用户不存在", null);
		}
		userEntity.setHeadimgurl(headimgurlPrefix + uid);
		return new ResultModel<UserEntity>(ResultModel.SUCCESS, "获取user成功", userEntity);
	}
	
	/**
	 * 2查uid最大值
	 * @return
	 */
	@RequestMapping(value = "queryMaxUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryMaxUid() {
		String maxUid = userService.queryMaxUid();
		return new ResultModel<String>(ResultModel.SUCCESS, "获取maxUid成功", maxUid);
	}
	
	/**
	 * 3根据uid排序 查该uid后1000条数据
	 * @param uid 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "queryUserListByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserListByUid(String uid,HttpServletRequest request) {
		if (StringUtils.isEmpty(uid)) {
			// 允许为空 ， 空的时候就是前1000条
			uid = null;
		}
		ArrayList<HashMap<String, Object>> userList = userService.queryUserListByUid(uid, null);
		if (userList != null && userList.size() != 0) {
			userList = userService.processHeadimgurlOfUserList(userList, headimgurlPrefix);
		}
		return new ResultModel<ArrayList<HashMap<String, Object>>>(ResultModel.SUCCESS, "获取user列表成功", userList);
	}
	
	/**
	 * 4通过uid查询角色信息
	 * 
	 * @param uid
	 *            用户id
	 * @return
	 */
	@RequestMapping(value = "queryUserRoleByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryRoleByUid(String uid,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数为空", null);
		}
		ArrayList<RoleEntity> roleEntityList = userService.queryRoleByUid(uid);
		return new ResultModel<ArrayList<RoleEntity>>(ResultModel.SUCCESS, "获取role列表成功", roleEntityList);
	}
	
	/**
	 * 5通过uid查询角色标签
	 * 
	 * @param uid
	 *            用户id
	 * @return
	 */
	@RequestMapping(value = "queryUserTagByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryTagByUid(String uid,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数为空", null);
		}
		ArrayList<TagEntity> TagEntityList = userService.queryTagByUid(uid);
		return new ResultModel<ArrayList<TagEntity>>(ResultModel.SUCCESS, "获取tag列表成功", TagEntityList);
	}
	
	/**
	 * 6通过uid查询 认证信息
	 * 查询 认证中和 认证成功的
	 * @param uid
	 *            用户id
	 * @return
	 */
	@RequestMapping(value = "queryUserVerifyByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryVerifyByUid(String uid,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数为空", null);
		}
		ArrayList<UserVerifyEntity> userVerifyEntityList = userService.queryVerifyByUid(uid);
		return new ResultModel<ArrayList<UserVerifyEntity>>(ResultModel.SUCCESS, "获取verify列表成功", userVerifyEntityList);
	}
	
	/**
	 * 13 验证用户信息,用户名和密码
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "checkUserInfo", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> checkUserInfo(String un,String pd){
		logger.debug("验证用户信息");
		if(StringUtils.isEmpty(un) || StringUtils.isEmpty(pd)) {
			logger.warn("验证出错,请求参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, ResultModel.ERR_PARAM_MSG, null);
		}
		return loginService.checkUserInfo(un,pd);
	}
	
	/**
	 * 7通过mts查询 认证信息
	 * 
	 * @param mts    
	 * @return
	 */
	@RequestMapping(value = "queryUserVerifyByMts", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserVerifyByMts(String mts,HttpServletRequest request) {
		if(StringUtils.isEmpty(mts)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数mts为空", null);
		}
		if(!DateUtils.isValidDate(mts, "yyyy-MM-dd")) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数mts格式错误", null);
		}else {
			mts = DateUtils.parseDateString(mts, "yyyy-MM-dd");
		}
		ArrayList<UserVerifyEntity> userVerifyEntityList = userService.queryUserVerifyByMts(mts);
		return new ResultModel<ArrayList<UserVerifyEntity>>(ResultModel.SUCCESS, "获取更新日期为："+mts+"的认证信息列表成功", userVerifyEntityList);
	}
	
	 /**
	  * 8根据uid 和 mts 查后1000条数据
	  * @param uid
	  * @param request
	  * @return
	  */
	@RequestMapping(value = "queryUserListByUidAndMts", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserListByUidAndMts(String uid,String mts,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)) {
			//允许为空 ， 空的时候就是前1000条
			uid=null;
		}
		if(StringUtils.isEmpty(mts)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数mts为空", null);
		}
		if(!DateUtils.isValidDate(mts, "yyyy-MM-dd")) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数mts格式错误", null);
		}else {
			mts = DateUtils.parseDateString(mts, "yyyy-MM-dd");
		}
		
		ArrayList<HashMap<String, Object>> userList = userService.queryUserListByUid(uid,mts);
		if(userList != null && userList.size()!=0) {
			userList = userService.processHeadimgurlOfUserList(userList,headimgurlPrefix);
		}
		return new ResultModel<ArrayList<HashMap<String, Object>>>(ResultModel.SUCCESS, "获取user列表成功", userList);
	}
	
	/**
	 * 9通过phone查询用户信息 
	 * 
	 */
	@RequestMapping(value = "queryUserInfoByPhone", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserInfoByPhone(String phone,HttpServletRequest request) {
		if(StringUtils.isEmpty(phone)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数为空", null);
		}
		Map<String,Object> userInfo = userService.queryUserInfoByPhone(phone,headimgurlPrefix);
		return new ResultModel<Map<String,Object>>(ResultModel.SUCCESS, "获取userInfo成功", userInfo);
	}
	
	/**
	 * 14根据uid 驳回梦想教师认证 
	 * 
	 */
	@RequestMapping(value = "rejectTeacherVerifyByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> rejectTeacherVerifyByUid(String uid,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取失败,请求参数为空", null);
		}
		return new ResultModel<String>(ResultModel.SUCCESS, "操作成功", userService.rejectTeacherVerifyByUid(uid));
	}
	
	/**
	 * 11根据用户名和密码 ，返回用户权限点
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "getUserResIds", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getUserResIds(String un,String pd){
		logger.debug("返回用户权限点");
		if(StringUtils.isEmpty(un) || StringUtils.isEmpty(pd)) {
			logger.warn("验证出错,请求参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, ResultModel.ERR_PARAM_MSG, null);
		}
		return userService.getUserResIds(un,pd);
	}
	
	/**
	 * 12根据用户名uid ，返回用户权限点
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "getResIds", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getResIds(String uid){
		logger.debug("返回用户权限点");
		if(StringUtils.isEmpty(uid.trim())) {
			logger.warn("验证出错,请求参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, ResultModel.ERR_PARAM_MSG, null);
		}
		return userService.getResIds(uid.trim());
	}
	
	/**
	 * 添加或更新学校
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateSchoolData", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> replaceSchoolData(HttpServletRequest request) {
		String sid = request.getParameter("sid");
		if(StringUtils.isEmpty(sid)) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "参数sid传值空", null);
		}
		String sname = request.getParameter("sname");
		if(StringUtils.isEmpty(sname) || StringUtils.isEmpty(sname.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "参数sname传值空", null);
		}
		String email = request.getParameter("email");
		if(!StringUtils.isEmpty(email) && !Utils.verifyEmail(email)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数sid传值空", null);
		}
		//若phone不为空&phone不符合手机规则  直接置为null
		String phone = request.getParameter("phone");
		if(!StringUtils.isEmpty(phone) && !Utils.verifyPhone(phone)) {
			phone = null;
		}
		int province = StringUtils.isEmpty(request.getParameter("province")) ? 0 : Integer.parseInt(request.getParameter("province"));
		int city = StringUtils.isEmpty(request.getParameter("city")) ? 0 : Integer.parseInt(request.getParameter("city"));
		int area = StringUtils.isEmpty(request.getParameter("area")) ? 0 : Integer.parseInt(request.getParameter("area"));
		//数据中心 0,10都对应学校类别'其他'
		int scId = StringUtils.isEmpty(request.getParameter("scId")) || "0".equals(request.getParameter("scId")) ? 10 : Integer.parseInt(request.getParameter("scId"));
		int dr = Integer.parseInt(request.getParameter("dr"));
		SchoolEntity schoolEntity = new SchoolEntity();
		schoolEntity.setSid(sid);
		schoolEntity.setSname(sname);
		schoolEntity.setEmail(email);
		schoolEntity.setPhone(phone);
		schoolEntity.setProvince(province);
		schoolEntity.setCity(city);
		schoolEntity.setArea(area);
		schoolEntity.setScId(scId);
		schoolEntity.setDr(dr);
		try {
			return schoolService.addOrUpdateSchool(schoolEntity);
		} catch (ADreamServiceException e) {
			logger.warn("添加或更新学校失败:" + e.getMessage());
			return new ResultModel<String>(ResultModel.ERR_SYS, "添加或更新学校失败," + e.getMessage(), null);
		}
	}
	
	/**
	 * 添加梦想中心数据
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateDream2020SchoolData", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> addOrUpdateDream2020SchoolData(String body,HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("添加或更新盒子学校失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "添加或更新盒子学校失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("name") || StringUtils.isEmpty(data.getString("name"))) {
			logger.warn("添加或更新盒子学校失败,name为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "添加或更新盒子学校失败,参数name为空", null);
		}
		if(!data.containsKey("schoolNumber") || StringUtils.isEmpty(data.getString("schoolNumber"))) {
			logger.warn("添加或更新盒子学校失败,schoolNumber为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "添加或更新盒子学校失败,参数schoolNumber为空", null);
		}
		if(!data.containsKey("email") || StringUtils.isEmpty(data.getString("email"))) {
			logger.warn("添加或更新盒子学校失败,email为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "添加或更新盒子学校失败,参数email为空", null);
		}
		Dream2020SchoolEntity dream2020SchoolEntity = new Dream2020SchoolEntity();
		dream2020SchoolEntity.setName(data.getString("name"));
		//设置首字母
		dream2020SchoolEntity.setFirstLetter(ChineseCharToEnUtil.getFirstLetter(data.getString("name").substring(0,1)).toUpperCase());
		dream2020SchoolEntity.setSponsors(data.getString("sponsors") == null ? "" : data.getString("sponsors"));
		dream2020SchoolEntity.setRemark(data.getString("remark") == null ? "" : data.getString("remark"));
		dream2020SchoolEntity.setSchoolNumber(data.getString("schoolNumber"));
		dream2020SchoolEntity.setEmail(data.getString("email"));
		dream2020SchoolEntity.setPhone(data.getString("phone") == null ? "" : data.getString("phone"));
		dream2020SchoolEntity.setZipCode(data.getString("zipCode") == null ? "" : data.getString("zipCode"));
		dream2020SchoolEntity.setProvince(!data.containsKey("province") ? 0 : data.getIntValue("province"));
		dream2020SchoolEntity.setCity(!data.containsKey("city") ? 0 : data.getIntValue("city"));
		dream2020SchoolEntity.setArea(!data.containsKey("area") ? 0 : data.getIntValue("area"));
		dream2020SchoolEntity.setLocation(data.getString("location") == null ? "" : data.getString("location"));
		dream2020SchoolEntity.setApplytime(!data.containsKey("applytime") ? 0L : data.getIntValue("applytime"));
		dream2020SchoolEntity.setTeacherCnt(!data.containsKey("teacherCnt") ? 0 : data.getIntValue("teacherCnt"));
		dream2020SchoolEntity.setStudentCnt(!data.containsKey("studentCnt") ? 0 : data.getIntValue("studentCnt"));
		dream2020SchoolEntity.setIsDel(!data.containsKey("isDel") ? 0 : data.getIntValue("isDel"));
		try {
			return dream2020SchoolService.addOrUpdateDream2020School(dream2020SchoolEntity);
		} catch (ADreamServiceException e) {
			logger.warn("添加或更新新版学校失败:" + e.getMessage());
			return new ResultModel<String>(ResultModel.ERR_SYS, "添加或更新新版学校失败," + e.getMessage(), null);
		}
	}
	
	/**
	 * 同步数据
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "synDreamData", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> synDreamData(String uid) {
		logger.debug("同步盒子数据");
		if(StringUtils.isEmpty(uid)) {
			logger.warn("同步出错,参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "同步出错,参数为空", null);
		}
		UserEntity user = basicInfoService.queryBasicInfo(uid);
		if(user == null) {
			logger.warn("同步出错,未查询到需要同步的数据:(");
			return new ResultModel<String>(ResultModel.NOT_FOUND_OBJECT, "未查询到需要同步的数据", null);
		}
		SynDataEntity data = new SynDataEntity();
		BeanUtils.copyProperties(user, data);
		if(user.getSex() != null) {
			data.setSex(data.getSex().equals(Constant.MALE) ? String.valueOf(Constant.ONE) : String.valueOf(Constant.TWO));
		}
		data.setProvince(user.getProvince() == null ? null : String.valueOf(user.getProvince()));
		data.setCity(user.getCity() == null ? null : String.valueOf(user.getCity()));
		data.setArea(user.getArea() == null ? null : String.valueOf(user.getArea()));
		data.setRealname(user.getRealName());
		data.setHeadimgurl(headimgurlPrefix + uid);
		
		//查询用户角色,权限
		UserRoleResModel userRoleRes = userService.queryUserRoleResByUid(uid, Constant.ONE);
		if(userRoleRes != null 
				&& !StringUtils.isEmpty(userRoleRes.getResIds())) {
			String resIds = userRoleRes.getResIds();
			if(resIds.indexOf(Constant.ADREAM_BOX_ADMIN) != -1) {
				data.setIsAdreamboxAdmin(true);					
			}
			if(resIds.indexOf(Constant.REALNAME_RES_ID) != -1) {
				data.setVerified(String.valueOf(Constant.ONE));
			}
		}
		
		WebServiceResponse result = synDataService.synData(data);
		if(!result.getSuccess().getValue()) {
			return new ResultModel<String>(ResultModel.ERR_PERMISSION, result.getStringResult().getValue(), null);
		}
		return new ResultModel<String>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, null);
	}
	
	/**
	 * 10分页 查用户 认证机构名字 
	 * @param uid
	 * @param pageNo 默认0
	 * @param pageSize 默认 10  最大值 20
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "queryUserVerifyInfo", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserVerifyInfo(String uid,Integer pageNo,Integer pageSize,HttpServletRequest request) {
		PageInfo<List<Map<String,Object>>> users = userService.queryUserVerifyInfo(uid,pageNo,pageSize,headimgurlPrefix);
		return new ResultModel<PageInfo<List<Map<String,Object>>>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, users);
	}
	/**
	 * 根据uid  查询 实名信息
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "queryRealName", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryRealName(String uid,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "参数uid传值空", null);
		}
		RealNameAuthEntity realNameAuthEntity = userService.queryRealName(uid.trim());
		if(realNameAuthEntity == null) {
			return new ResultModel<String>(ResultModel.NOT_FOUND_OBJECT, "没有实名信息", null);
		}
		//不需要返回的清空掉
		realNameAuthEntity.setCreType(null);
		realNameAuthEntity.setCreNum(null);
		realNameAuthEntity.setCreFrontPic(null);
		realNameAuthEntity.setCreReversePic(null);
 
		return new ResultModel<RealNameAuthEntity>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, realNameAuthEntity);
		 
	}
	
	/**
	 * 根据unionid查用户 相关信息 
	 * 弃用的 （不知道有没有地方用到 先保留）
	 * @param unionid
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "queryUserInfoByUnionid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserInfoByUnionid(String unionid,HttpServletRequest request) {
		return userService.queryUserInfoByUnionid(unionid,request);
	}
	
	/**
	 * 根据uid查询用户教练计划认证角色
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "queryUserCoachPlanRole", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserCoachPlanRole(String uid) {
		if(StringUtils.isEmpty(uid)) {
			logger.warn("查询用户教练计划认证角色失败:uid为空");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询出错,参数有误", null);
		}
		return verifyService.queryUserCoachPlanRole(uid);
	}
	
	/**
	 *	根据uid查询用户基本信息,角色,权限,实名认证,身份认证信息
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "querySomeUserInfo", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> querySomeUserInfo(String uid) {
		if(StringUtils.isEmpty(uid)) {
			logger.warn("查询用户信息失败:uid为空");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询出错,参数有误", null);
		}
		return userService.queryUserInfo(uid);
	}
	
	/**
	 *	根据uids查询梦想教师用户信息  用于任务系统五星报表导出
	 * @param uids
	 * @return
	 */
	@RequestMapping(value = "querySomeTeacherUserInfos", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> querySomeTeacherUserInfos(String uids) {
		if(StringUtils.isEmpty(uids)) {
			logger.warn("查询用户信息失败:uids为空");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询出错,参数有误", null);
		}
		return userService.queryTeacherUserInfos(uids.split(","));
	}
	
	/**
	 * 根据uids查询用户信息 
	 * @param uids
	 * @return
	 */
	@RequestMapping(value = "queryUserInfos", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserInfos(String uids) {
		if(StringUtils.isEmpty(uids)) {
			logger.warn("查询用户信息失败:uids为空");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询出错,参数有误", null);
		}
		return userService.queryUserInfos(uids.split(","));
	}
	/**
	 * 根据用户名uid ，返回用户角色ID 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "getRoleIds", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getRoleIds(String uid){
		logger.debug("返回用户角色IDs");
		if(StringUtils.isEmpty(uid.trim())) {
			logger.warn("验证出错,请求参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, ResultModel.ERR_PARAM_MSG, null);
		}
		return userService.getRoleIds(uid.trim());
	}
	
	/**
	 * replace用户-角色
	 * @param uid
	 * @param rleId
	 * @return
	 */
	@RequestMapping(value = "replaceUserRole", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> replaceUserRole(String uid, String rleId) {
		if(StringUtils.isEmpty(uid) || StringUtils.isEmpty(rleId)) {
			logger.warn("添加用户-角色失败,参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "添加失败,参数为空", null);
		}
		return userService.replaceUserRoleById(uid, rleId);
	}
	
	/**
	 * 20.
	 * 发送短信验证码
	 * @param phone
	 * @param sendCode
	 * @return
	 */
	@RequestMapping(value = "sendSMS", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> sendSMS(String phone, String sendCode) {
		if(StringUtils.isEmpty(phone) || StringUtils.isEmpty(sendCode)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "发送失败,参数error", null);
		}
		if(!Utils.verifyPhone(phone.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "发送失败,手机号格式错误", null);
		}
		// 调用接口发送短信
		try {
			HashMap<String, Object> result = SDKTestSendTemplateSMS.instance.sendMSMinfoNoCheck(phone, sendCode);
			String statusCode = String.valueOf(result.get("statusCode"));

			if (!"000000".equals(statusCode)) {
//				String rlt = String.valueOf(result.get("statusMsg"));
				return new ResultModel<HashMap<String, Object>>(ResultModel.ERR_SERVICE, "第三方返回错误", result);
			}
		} catch (ADreamServiceException e) {
			return new ResultModel<String>(ResultModel.ERR_SYS, "发送失败,sys error", null);
		}
		 return new ResultModel<String>(ResultModel.SUCCESS, "发送成功", null);
	}
	
	/**
	 * 21 火堆使用  （返回火堆的3种角色认证信息）
	 *	 获取用户信息
	 * @param unionid
	 * @param rleId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getUserInfoByUnionid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getUserInfoByUnionid(String unionid,String rleId,HttpServletRequest request) {
		if(StringUtils.isEmpty(unionid)||StringUtils.isEmpty(unionid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid空值", null);
		}
		if(StringUtils.isEmpty(rleId)||StringUtils.isEmpty(rleId.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "rleId空值", null);
		}
		return userService.getUserInfoByUnionid(unionid,rleId,request);
	}
	
	/**
	 * 22火堆使用
	 * 根据手机号查询  当unionid 不一致时 替换unionid 若unionid对应的其他用户存在 则不能查询
	 * @param phone
	 * @param unionid
	 * @param rleId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getUserInfoAndBindUnionidByPhone", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getUserInfoAndBindUnionidByPhone(String phone,String unionid,String rleId,HttpServletRequest request) {
		if (StringUtils.isEmpty(phone) || StringUtils.isEmpty(phone.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "手机号phone参数错误", null);
		}
		if (StringUtils.isEmpty(unionid) || StringUtils.isEmpty(unionid.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid参数错误", null);
		}
		if(StringUtils.isEmpty(rleId)||StringUtils.isEmpty(rleId.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "rleId空值", null);
		}
		return userService.getUserInfoAndBindUnionidByPhone(phone,unionid,rleId,request);
	}
	
	/**
	 * 火堆使用
	 * @param request
	 * @param unionid 
	 * @param rleId 角色ID （社会组织，企业，公益团队）
	 * @param realNameInfoJson 实名信息json字符串  
	 * 		  (uid,phone,realName,creType,creNum,creFrontPicUrl,creReversePicUrl)
	 * @param IdentityInfoJson 身份信息json字符串
	 * 		  (company,creCode,crePicUrl,intro,wechat,contact,phone)
	 * @param bankInfoJson 银行卡信息json字符串
	 * 		  (accountName,depositBank,aopenBranch,bankAccount)
	 * @return
	 */
	@RequestMapping(value = "saveUserInfo", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> saveUserInfo(HttpServletRequest request,String unionid,String rleId
			,String realNameInfoJson,String IdentityInfoJson,String bankInfoJson) {
		if(StringUtils.isEmpty(unionid)||StringUtils.isEmpty(unionid.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid参数空值", null);
		}
		if(StringUtils.isEmpty(rleId)||StringUtils.isEmpty(rleId.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "rleId参数空值", null);
		}
		if(StringUtils.isEmpty(realNameInfoJson)||StringUtils.isEmpty(realNameInfoJson.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "realNameInfoJson参数空值", null);
		}
		if(StringUtils.isEmpty(IdentityInfoJson)||StringUtils.isEmpty(IdentityInfoJson.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "IdentityInfoJson参数空值", null);
		}
		if(StringUtils.isEmpty(bankInfoJson)||StringUtils.isEmpty(bankInfoJson.trim())) {
			 return new ResultModel<String>(ResultModel.ERR_PARAM, "IdentityInforJson参数空值", null);
		}
		switch (rleId) {
		case Constant.BUSINESS_ROLE_ID: //企业
			break;
		case Constant.ORG_ROLE_ID:  //社会组织
			break;
		case Constant.PUBLIC_WELFARE_TEAM_ROLE_ID:  //公益团队
			break;
		default:
			return new ResultModel<String>(ResultModel.ERR_PARAM, "身份类型非法", null);
		}
		JSONObject realNameObject = JSONObject.parseObject(realNameInfoJson);
		JSONObject IdentityInfoObject = JSONObject.parseObject(IdentityInfoJson);
		JSONObject bankInfoObject = JSONObject.parseObject(bankInfoJson);
		 
		String uid = realNameObject.getString("uid");
		if(StringUtils.isEmpty(uid)||StringUtils.isEmpty(uid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "负责人uid空值", null);
		}
		String phone  = realNameObject.getString("phone");
		if(StringUtils.isEmpty(phone)||StringUtils.isEmpty(phone.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "负责人phone空值", null);
		}
		String creType = realNameObject.getString("creType");
		if(StringUtils.isEmpty(creType)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "creType空值", null);
		}
		switch (creType.trim()) {
		case "1":
		case "0":	
			break;
		default:
			return new ResultModel<String>(ResultModel.ERR_PARAM, "creType非法", null);
		}
		String logId = IdGenerator.getGuid();
		try {
			LogRestfulEntity entity =  new LogRestfulEntity();
			entity.setLogId(logId);
			entity.setApiPath("/saveUserInfo");
			String content = request.getParameter("body");
			entity.setContent(content);
			entity.setUsedBy("huodui");
			if(logRestfulService.addEntity(entity)==1) {
				asyncService.asyncSaveUserInfo(logId,unionid,rleId,realNameObject,IdentityInfoObject,bankInfoObject);
				return new ResultModel<String>(ResultModel.SUCCESS, "操作成功", null);
			}else {
				return new ResultModel<String>(ResultModel.ERR_SYS, "操作失败", null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultModel<String>(ResultModel.ERR_SYS, ResultModel.ERR_SYS_MSG, null);
		}
	}

	/**
	 * 24 火堆使用
	 * 获取身份角色信息  3种身份（社会组织，企业，公益组织） 是否能认证
	 * 错误码1004  不能认证已被其他身份认证
	 * 0000  如果有返回数据returnObject 就是认证过了 没有就是新认证用户 
	 * 
	 * @param unionid
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getRoleInfoByUnionid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getRoleInfoByUnionid(String unionid,HttpServletRequest request) {
		if(StringUtils.isEmpty(unionid)||StringUtils.isEmpty(unionid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid空值", null);
		}
		try {
			return verifyService.getRoleInfoByUnionid(unionid,request);
		} catch (ADreamServiceException e) {
			return new ResultModel<String>(ResultModel.ERR_SYS, ResultModel.ERR_SYS_MSG, null);
		}
	}
	
	/**
	 * 25检查手机号是否被 unionid以外的人占用
	 * @param unionid
	 * @param phone
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "checkPhone", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> checkPhone(String unionid,String phone) {
		if(StringUtils.isEmpty(unionid)||StringUtils.isEmpty(unionid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid空值", null);
		}
		if(StringUtils.isEmpty(phone)||StringUtils.isEmpty(phone.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "phone空值", null);
		}
		Boolean flag = userService.checkPhoneNotUsedByUnionid(unionid,phone);
		if(flag) {
			return new ResultModel<String>(ResultModel.SUCCESS, "可以使用", null);
		}
		return new ResultModel<String>(ResultModel.ERR_USER_INFO, "已被他人使用", null);
	}
	
	/**
	 * 26审核认证并同步数据
	 * @param uid			用户id
	 * @param rleId			角色id
	 * @param state			认证状态
	 * @param checkResult	审核说明
	 * @return
	 */
	@RequestMapping(value = "checkVerifyAndSynData", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> checkVerifyAndSynData(String uid, String rleId, Integer state, String checkResult) {
		UserVerifyEntity verifyEntity = new UserVerifyEntity();
		verifyEntity.setUid(uid);
		verifyEntity.setRleId(rleId);
		verifyEntity.setState(state);
		verifyEntity.setCheckResult(checkResult);
		return verifyService.checkVerifyAndSynData(null,verifyEntity.getUid(),verifyEntity.getRleId(), verifyEntity);
	}
	
	/**
	 * 获取用户详细信息
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "getUserDetailByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<UserDetailEntity> getUserDetailByUid(String uid) {
		UserDetailEntity userDetailEntity = userDetailService.queryUserDetailByUid(uid);
		if(userDetailEntity == null) {
			return new ResultModel<UserDetailEntity>(ResultModel.NOT_FOUND_OBJECT, "查询失败,用户不存在", null);
		}
		return new ResultModel<UserDetailEntity>(ResultModel.SUCCESS, "查询成功", userDetailEntity);
	}
	
	/**
	 *	 目前火堆使用  modifer 写的火堆
	 * 
	 * accountName账户名，bankAccount银行账号，depositBank开户行，aopenBranch开户支行
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "updateBankInfo", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> updateBankInfo(String uid,String accountName,String bankAccount,String depositBank,String aopenBranch) {
		if(StringUtils.isEmpty(uid)||StringUtils.isEmpty(uid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "uid丢失", null);
		}
		return userDetailService.updateBankInfo(uid,accountName,bankAccount,depositBank,aopenBranch);
	}
	
	/**
	 * 更新用户手机号
	 * @param unionid
	 * @param phone
	 * @return
	 */
	 
	@RequestMapping(value = "updatePhone", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> updatePhone(String unionid,String phone) {
		if(StringUtils.isEmpty(unionid)||StringUtils.isEmpty(unionid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid空值", null);
		}
		if(StringUtils.isEmpty(phone)||StringUtils.isEmpty(phone.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "phone空值", null);
		}
		Boolean flag = userService.checkPhoneNotUsedByUnionid(unionid,phone);
		if(!flag) {
			return new ResultModel<String>(ResultModel.ERR_USER_INFO, "手机号已被他人使用", null);
		} 
		Integer rlt = userService.updateUserPhoneByUnionid(unionid,phone);
		if(rlt == null || rlt != 1) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "unionid对应的用户不存在，请检查", null);
		}
		return new ResultModel<String>(ResultModel.SUCCESS, "更新成功", null);
	}
	/**
	 *	25. 获取全部系统角色 
	 * @return{rleId:[角色ID],rleName:[角色名],rleDesc:[角色描述]}
	 */
	@RequestMapping(value = "getSysRoleInfo", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getSysRoleInfo() {
		try {
			List<Map<String,Object>> list = roleService.getSysRoleInfo();
			return new ResultModel<List<Map<String,Object>>>(ResultModel.SUCCESS,ResultModel.SUCCESS, list);
		} catch (ADreamServiceException e) {
			logger.error(e.getMessage());
			return new ResultModel<String>(ResultModel.ERR_SYS, ResultModel.ERR_SYS_MSG, e.getMessage());
		}
	}
	
	/**
	 *  26	根据条件查询 用户列表
	 * @param realName 真实姓名 (模糊搜索)( 非必填，默认为没有 )
	 * @param schoolName 学校名称 (模糊搜索)( 非必填，默认为没有 )
	 * @param phone 手机号  ( 非必填，默认为没有 ) 
	 * @param rleId 角色ID  ( 非必填，默认为没有 ) 
	 * @param page 第几页   ( 非必填，默认为0，第一页为0 )
	 * @param count 最多返回条数( 非必填，默认为20  ,最少10，最多100)
	 * @param areaId 地区ID ( 可以是省市区任意 )
	 * @return
	 */
	@RequestMapping(value = "queryUserList", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> queryUserList(String realName,String schoolName,String phone,
			String rleId,String page,String count,String areaId) {
		PageInfo<Map<String,Object>> pageInfo = userService.queryUserList(realName,schoolName, phone, rleId, page, count, areaId);
		return new ResultModel<PageInfo<Map<String,Object>>>(ResultModel.SUCCESS,ResultModel.SUCCESS,pageInfo);
	}
	
	/**
	 * 获取用户地址
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "getUserAddress", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getUserAddress(String uid) {
		if(StringUtils.isEmpty(uid)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数错误", null);
		}
		try {
			List<UserAddressEntity> list = userAddressService.searchByUid(uid);
			return new ResultModel<List<UserAddressEntity>>(ResultModel.SUCCESS, "查询成功", list);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return new ResultModel<String>(ResultModel.ERR_SYS, ResultModel.ERR_SYS_MSG, e.getMessage());
		}
	}

	/**
	 * replace 地区
	 * @param areaId 地区id
	 * @param title	地区名称
	 * @param pid	父id
	 * @param aSort	排序值
	 * @return
	 */
	@RequestMapping(value = "replaceArea", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> replaceArea(int areaId, String title, int pid, int aSort) {
		if(areaId == 0 || StringUtils.isEmpty(title) || aSort == 0) {
			logger.warn("replace地区失败,参数有误:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新地区失败,参数为空", null);
		}
		AreaEntity area = new AreaEntity();
		area.setAreaId(areaId);
		area.setTitle(title);
		area.setPid(pid);
		area.setaSort(aSort);
		return areaService.replaceArea(area);
	}
	
	/**
	 * 根据uid获取梦想教师星级
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "getTeacherStarByUid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<?> getTeacherStarByUid(String uid) {
		if(StringUtils.isEmpty(uid) || StringUtils.isEmpty(uid.trim())) {
			logger.warn("获取梦想教师星级错误,uid为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "获取梦想教师星级错误,参数为空", null);
		}
		ResultModel<?> resultModel = userService.getRoleIds(uid);
		if(!ResultModel.SUCCESS.equals(resultModel.getReturnCode())) {
			logger.warn("获取梦想教师星级错误," + resultModel.getReturnMessage());
			return new ResultModel<String>(resultModel.getReturnCode(), "查询失败", null);
		}
		List<?> rleIds = (List<?>) resultModel.getReturnObject();
		//角色为空或无梦想教师角色
		if(Utils.isEmptyCollection(rleIds) || !rleIds.contains(Constant.TEACHER_ROLE_ID)) {
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, -1);
		} else if(rleIds.contains(Constant.FIVE_STAR_ADREAM_ROLE_ID)) {				
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, Constant.FIVE);
		} else if(rleIds.contains(Constant.FOUR_STAR_ADREAM_ROLE_ID)) {				
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, Constant.FOUR);
		} else if(rleIds.contains(Constant.THREE_STAR_ADREAM_ROLE_ID)) {				
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, Constant.THREE);
		} else if(rleIds.contains(Constant.TWO_STAR_ADREAM_ROLE_ID)) {				
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, Constant.TWO);
		} else if(rleIds.contains(Constant.ONE_STAR_ADREAM_ROLE_ID)) {				
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, Constant.ONE);
		} else {
			//梦想教师认证已认证成功&一星任务未完成
			return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, Constant.ZERO);
		}
	}
	
	/**
	 * 获取用户相关信息
	 * 智慧课堂使用
	 * @param uid 用户标识
	 * @return
	 */
	@RequestMapping(value = "getUserInfoByUid", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getUserInfoByUid (String uid) {
		if(StringUtils.isEmpty(uid)||StringUtils.isEmpty(uid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数不存在", null);
		}
		UserEntity userEntity = null;
		userEntity = userService.queryUserByUid(uid.trim());
		if(userEntity == null) {
			return new ResultModel<UserVO>(ResultModel.NOT_FOUND_OBJECT, "查询失败,用户不存在", null);
		}
		UserVO userVO = new UserVO();
		Utils.copyPropertiesIgnoreNull(userEntity, userVO);
		
		if(StringUtils.isEmpty(userVO.getUid())) {
			return new ResultModel<String>(ResultModel.ERR_SYS, ResultModel.ERR_SYS_MSG, null);
		}
		RealNameAuthEntity realNameAuthEntity = null;
		realNameAuthEntity = realNameAuthService.queryAuthByUid(userVO.getUid());
		if(realNameAuthEntity != null) {
			userVO.setRealName(realNameAuthEntity.getRealName());
		}
		SchoolEntity schoolEntity = schoolService.queryMySchoolByUid(userVO.getUid());
		if(schoolEntity !=null) {
			userVO.setSid(schoolEntity.getSid());
			userVO.setSname(schoolEntity.getSname());
			userVO.setProvince(schoolEntity.getSchoolProvince());
			userVO.setCity(schoolEntity.getSchoolCity());
			userVO.setArea(schoolEntity.getSchoolArea());
		}
		try {
			userVO = handleData(userVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return new ResultModel<UserVO>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, userVO);
	}
	
	/**
	 * 	银行卡号信息 等
	 * @param uid
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "getBankInfoByUid", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getBankInfoByUid (String uid) {
		if(StringUtils.isEmpty(uid)||StringUtils.isEmpty(uid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数不存在", null);
		}
		UserDetailEntity userDetailEntity = userDetailService.queryUserDetailByUid(uid);
		if(userDetailEntity == null) {
			return new ResultModel<BankVO>(ResultModel.NOT_FOUND_OBJECT, "查询失败,用户不存在", null);
		}
		BankVO bankVO = new BankVO();
		if(userDetailEntity != null) {
			Utils.copyPropertiesIgnoreNull(userDetailEntity, bankVO);
		}
		try {
			bankVO = handleData(bankVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		//无奈 再查下area -title
		if(bankVO.getAopenProvince()!=null && bankVO.getAopenProvince()!=0) {
			AreaEntity province = areaService.queryAreaById(bankVO.getAopenProvince());
			bankVO.setAopenProvinceString(province.getTitle());
		}
		if(bankVO.getAopenCity()!=null && bankVO.getAopenCity()!=0) {
			AreaEntity city = areaService.queryAreaById(bankVO.getAopenCity());
			bankVO.setAopenCityString(city.getTitle());
		}
		return new ResultModel<BankVO>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, bankVO);
	}
	
	/**
	 * 本接口供联想使用
	 * 梦想中心数量从2020-12-27号开始统计
	 * @param position null或者小于0时 默认0
	 * @param count null或者小于10或者大于1000时 默认1000
	 * @return
	 */
	@RequestMapping(value = "getSchoolsInfo", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getSchoolsInfo (Integer position,Integer count,String timestamp) {
		if(position==null || position <0 ) {
			position = 0;
		}
		if(count==null || count <10 || count>1000) {
			count = 1000;
		}
		String time = null;
		if(StringUtils.isEmpty(timestamp)||StringUtils.isEmpty(timestamp.trim())) {
			time = null;
		} else {
			if(timestamp.length() != 13) {
				return new ResultModel<List<SchoolVO>>(ResultModel.ERR_PARAM, "时间戳长度错误", null);
			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			time = sdf.format(new Date(Long.parseLong(timestamp)));
		}
		
		List<SchoolVO> schoolList = schoolService.querySchoolsInfo(position,count,time);
		return new ResultModel<List<SchoolVO>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, schoolList);
	}
	 
	/**
	 * 
	 * @param username
	 * @param password  RSA 密文
	 * @return
	 */
	@RequestMapping(value = "doLogin", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> doLogin (String username,String password) {
		if(StringUtils.isEmpty(username)||StringUtils.isEmpty(password)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, ResultModel.ERR_PARAM_MSG,null);
		}
		String pwdString = null;
		try {
			Map<Integer, String> keyMap = RSACoderUtil.instance.initKey();
			pwdString = RSACoderUtil.instance.decrypt(password, keyMap.get(1));
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultModel<String>(ResultModel.ERR_SYS, "解密算法错误",null);
		}
		if(StringUtils.isEmpty(pwdString)) {
			return new ResultModel<String>(ResultModel.ERR_USER_INFO, "用户名或密码错误",null);
		}
		UserVO userVO =  loginService.doLogin(username,pwdString);
		if(userVO == null) {
			return new ResultModel<String>(ResultModel.ERR_USER_INFO, "用户名或密码错误",null);
		}
		try {
			userVO = handleData(userVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResultModel<UserVO>(ResultModel.SUCCESS, "登陆成功",userVO);
	}
	
	/**
	 * 新增或更新捐赠方
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateDonornData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> addOrUpdateDonornData(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("新增或更新捐赠方失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("id") || StringUtils.isEmpty(data.getString("id"))) {
			logger.warn("新增或更新捐赠方失败,id为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方失败,id为空", null);
		}
		if(!data.containsKey("name") || StringUtils.isEmpty(data.getString("name"))) {
			logger.warn("新增或更新捐赠方失败,name为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方失败,name为空", null);
		}
		DonornEntity donornEntity = new DonornEntity();
		donornEntity.setId(data.getString("id"));
		donornEntity.setName(data.getString("name"));
		donornEntity.setAddress(data.getString("address"));
		donornEntity.setProvince(!data.containsKey("province") ? 0 : data.getIntValue("province"));
		donornEntity.setCity(!data.containsKey("city") ? 0 : data.getIntValue("city"));
		donornEntity.setArea(!data.containsKey("area") ? 0 : data.getIntValue("area"));
		donornEntity.setType(data.getString("type"));
		donornEntity.setInfo(data.getString("info"));
		donornEntity.setEmail(data.getString("email"));
		donornEntity.setPhone(data.getString("phone"));
		donornEntity.setCts(!data.containsKey("cts") ? new Date() : DateUtils.string2Date(data.getString("cts"), "yyyy-MM-dd"));
		donornEntity.setDr(!data.containsKey("dr") ? 1 : data.getIntValue("dr") == 1 ? 0 : 1);
		return donornService.addOrUpdateDonorn(donornEntity);
	}
	
	/**
	 * 新增或更新新版盒子捐赠方
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateDream2020DonornData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> addOrUpdateDream2020DonornData(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("新增或更新新版盒子捐赠方失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子捐赠方失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("id") || StringUtils.isEmpty(data.getString("id"))) {
			logger.warn("新增或更新新版盒子捐赠方失败,id为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子捐赠方失败,id为空", null);
		}
		if(!data.containsKey("name") || StringUtils.isEmpty(data.getString("name"))) {
			logger.warn("新增或更新新版盒子捐赠方失败,name为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子捐赠方失败,name为空", null);
		}
		
		Dream2020DonornEntity dream2020DonornEntity = new Dream2020DonornEntity();
		dream2020DonornEntity.setId(data.getString("id"));
		dream2020DonornEntity.setName(data.getString("name"));
		dream2020DonornEntity.setAddress(data.getString("address"));
		dream2020DonornEntity.setProvince(!data.containsKey("province") ? 0 : data.getIntValue("province"));
		dream2020DonornEntity.setCity(!data.containsKey("city") ? 0 : data.getIntValue("city"));
		dream2020DonornEntity.setArea(!data.containsKey("area") ? 0 : data.getIntValue("area"));
		dream2020DonornEntity.setType(data.getString("type"));
		dream2020DonornEntity.setInfo(data.getString("info"));
		dream2020DonornEntity.setEmail(data.getString("email"));
		dream2020DonornEntity.setPhone(data.getString("phone"));
		dream2020DonornEntity.setCreateTime(!data.containsKey("cts") ? new Date() : DateUtils.string2Date(data.getString("cts"), "yyyy-MM-dd"));
		dream2020DonornEntity.setDeleteTime(!data.containsKey("dr") ? null : data.getIntValue("dr") == 1 ? new Date(data.getLongValue("ts")) : null);
		return dream2020DonornService.addOrUpdateDream2020Donorn(dream2020DonornEntity);
	}
	
	/**
	 * 新增或更新梦想中心
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateSchoolDreamCenterData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> addOrUpdateSchoolDreamCenterData(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("新增或更新梦想中心失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新梦想中心失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("dcid") || StringUtils.isEmpty(data.getString("dcid"))) {
			logger.warn("新增或更新梦想中心失败,dcid参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新梦想中心失败,dcid为空", null);
		}
		if(!data.containsKey("dcName") || StringUtils.isEmpty(data.getString("dcName"))) {
			logger.warn("新增或更新梦想中心失败,dcName参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新梦想中心失败,dcName为空", null);
		}
		if(!data.containsKey("sid") || StringUtils.isEmpty(data.getString("sid"))) {
			logger.warn("新增或更新梦想中心失败,sid参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新梦想中心失败", null);
		}
		DreamCenterEntity dreamCenterEntity = new DreamCenterEntity();
		dreamCenterEntity.setDcid(data.getString("dcid"));
		dreamCenterEntity.setDcName(data.getString("dcName"));
		dreamCenterEntity.setSid(data.getString("sid"));
		dreamCenterEntity.setSponsors(data.getString("sponsors"));
		dreamCenterEntity.setConfirmDate(StringUtils.isEmpty(data.getString("confirmDate")) ? null : DateUtils.string2Date(data.getString("confirmDate"), "yyyy-MM-dd"));
		dreamCenterEntity.setCts(new Date());
		dreamCenterEntity.setDr(!data.containsKey("dr") ? 1 : data.getIntValue("dr") == 1 ? 0 : 1);
		return dreamCenterService.addOrUpdateDreamCenter(dreamCenterEntity);
	}
	
	/**
	 * 新增或更新新版盒子梦想中心
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateDream2020SchoolDreamCenterData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> addOrUpdateDream2020SchoolDreamCenterData(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("新增或更新新版盒子梦想中心失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新梦想中心失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("id") || StringUtils.isEmpty(data.getString("id"))) {
			logger.warn("新增或更新新版盒子梦想中心失败,id参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子梦想中心失败,id为空", null);
		}
		if(!data.containsKey("name") || StringUtils.isEmpty(data.getString("name"))) {
			logger.warn("新增或更新新版盒子梦想中心失败,dcName参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子梦想中心失败,name为空", null);
		}
		if(!data.containsKey("schoolNumber") || StringUtils.isEmpty(data.getString("schoolNumber"))) {
			logger.warn("新增或更新新版盒子梦想中心失败,schoolNumber参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新梦想中心失败,schoolNumber为空", null);
		}
		Dream2020DreamCenterEntity dream2020DreamCenterEntity = new Dream2020DreamCenterEntity();
		dream2020DreamCenterEntity.setId(data.getString("id"));
		dream2020DreamCenterEntity.setName(data.getString("name"));
		dream2020DreamCenterEntity.setSchoolNumber(data.getString("schoolNumber"));
		dream2020DreamCenterEntity.setSponsors(data.getString("sponsors"));
		dream2020DreamCenterEntity.setCtime(new Date());
		dream2020DreamCenterEntity.setIsDel(data.getIntValue("dr"));
		return dream2020DreamCenterService.addOrUpdateDream2020DreamCenter(dream2020DreamCenterEntity);
	}
	
	/**
	 * 新增或更新捐赠方-梦想中心
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateDonornDreamCenterData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> addOrUpdateDonornDreamCenterData(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("新增或更新捐赠方-梦想中心失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方-梦想中心失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("donornId") || StringUtils.isEmpty(data.getString("donornId"))) {
			logger.warn("新增或更新捐赠方-梦想中心失败,donornId参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方-梦想中心失败,donornId为空", null);
		}
		if(!data.containsKey("dcid") || StringUtils.isEmpty(data.getString("dcid"))) {
			logger.warn("新增或更新捐赠方-梦想中心失败,dcid参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方-梦想中心失败,dcid为空", null);
		}
		
		DonornDreamCenterLinkEntity donornDreamCenterLinkEntity = new DonornDreamCenterLinkEntity();
		donornDreamCenterLinkEntity.setDonornId(data.getString("donornId"));
		donornDreamCenterLinkEntity.setDcid(data.getString("dcid"));
		donornDreamCenterLinkEntity.setDr(!data.containsKey("dr") ? 1 : data.getIntValue("dr") == 1 ? 0 : 1);
		return dreamCenterService.addOrUpdateDonornDreamCenter(donornDreamCenterLinkEntity);
	}
	
	/**
	 * 新增或更新新版盒子捐赠方-梦想中心
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "addOrUpdateDream2020DonornDreamCenterData", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> addOrUpdateDream2020DonornDreamCenterData(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("新增或更新新版盒子捐赠方-梦想中心失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新捐赠方-梦想中心失败,参数为空", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("donornId") || StringUtils.isEmpty(data.getString("donornId"))) {
			logger.warn("新增或更新新版盒子捐赠方-梦想中心失败,donornId参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子捐赠方-梦想中心失败,donornId为空", null);
		}
		if(!data.containsKey("dcid") || StringUtils.isEmpty(data.getString("dcid"))) {
			logger.warn("新增或更新新版盒子捐赠方-梦想中心失败,dcid参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "新增或更新新版盒子捐赠方-梦想中心失败,dcid为空", null);
		}
		Dream2020DonornDreamCenterLinkEntity dream2020DonornDreamCenterLinkEntity = new Dream2020DonornDreamCenterLinkEntity();
		dream2020DonornDreamCenterLinkEntity.setDonornId(data.getString("donornId"));
		dream2020DonornDreamCenterLinkEntity.setDcid(data.getString("dcid"));
		dream2020DonornDreamCenterLinkEntity.setDeleteTime(!data.containsKey("dr") || data.getIntValue("dr") != 1 ? null : DateUtils.string2Date(data.getString("ts"), "yyyy-MM-dd HH:mm:ss"));
		return dream2020DreamCenterService.addOrUpdateDream2020DonornDreamCenter(dream2020DonornDreamCenterLinkEntity);
	}
	
	/**
	 * 获取用户梦想课时数
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "getDream2020UserCourseTimeNum", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<Integer> getDream2020UserCourseTimeNum(String uid, HttpServletRequest request) {
		uid = !StringUtils.isEmpty(uid) ? uid : UserUtil.getUidByRequest(request);
		if(StringUtils.isEmpty(uid)) {
			logger.warn("获取失败,uid为空:(");
			return new ResultModel<Integer>(ResultModel.ERR_PARAM, "获取失败,参数为空", 0);
		}
		return dream2020UserService.queryDream2020UserCourseTimeNumByCasId(uid);
	}
	
	/**
	 * 获取用户开课记录数
	 * @param uid
	 * @param ts
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getDream2020UserSetUpCourseNum", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultModel<Integer> getDream2020UserSetUpCourseNum(String uid, Long ts, HttpServletRequest request) {
		uid = !StringUtils.isEmpty(uid) ? uid : UserUtil.getUidByRequest(request);
		if(StringUtils.isEmpty(uid)) {
			logger.warn("获取失败,uid为空:(");
			return new ResultModel<Integer>(ResultModel.ERR_PARAM, "获取失败,参数为空", 0);
		}
		//ts不为null && ts是13位的时间戳，转为10位的
		if(ts != null && ts.toString().length() == 13) {
			ts = ts / 1000;
		}
		return dream2020UserService.queryDream2020UserSetUpCourseNumByCasId(uid, ts);
	}
	
	/**
	 * 
	 * @param name  姓名/手机号  注：手机号后期加上的，因此 名字就没改
	 * @param page  页面  （默认 第1页）
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getUserInfoByName", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getUserInfoByName (String name,Integer page,HttpServletRequest request) {
		PageInfo<UserEntity> pageInfo = userService.getUserInfoByNameOrPhone(name, page);
		return new ResultModel<PageInfo<UserEntity>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, pageInfo);
	}
	
	
	/**
	 * 	根据 uids 查询用户手机
	 * @param uids
	 * @return
	 */
	@RequestMapping(value = "getPhonesByUids", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getPhonesByUids (String uids) {
		if(StringUtils.isEmpty(uids)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数为空", null);
		}
		List<String> uidList = JSONObject.parseArray(uids, String.class);
		if(uidList == null || uidList.isEmpty()) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数为空1", null);
		}
		if(uidList.size()>1000) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询对象过多", null);
		}
		List<Map<String, Object>> rlt = userService.getPhonesByUids(uidList);
		return new ResultModel<List<Map<String, Object>>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, rlt);
	}
	
	/**
	 * 	根据 phones 查询用户手机
	 * @param phones
	 * @return
	 */
	@RequestMapping(value = "getUidsByPhones", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getUidsByPhones (String phones) {
		if(StringUtils.isEmpty(phones)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数为空", null);
		}
		List<String> phoneList = JSONObject.parseArray(phones, String.class);
		if(phoneList == null || phoneList.isEmpty()) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "参数为空1", null);
		}
		if(phoneList.size()>1000) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询对象过多", null);
		}
		List<Map<String, Object>> rlt = userService.getUidsByPhones(phoneList);
		return new ResultModel<List<Map<String, Object>>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, rlt);
	}
	
	/**
	 * 	更新用户部分基本信息  若为空则不更新
	 * @param uid 该参数不能为空
	 * @param avatarUrl
	 * @param nickname
	 * @param sex
	 * @return
	 */
	@RequestMapping(value = "updateUserBasicInfo", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> updateUserBasicInfo (String uid,String avatarUrl,String nickname,String sex,HttpServletRequest request) {
		if(StringUtils.isEmpty(uid)||StringUtils.isEmpty(uid.trim())) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, ResultModel.ERR_PARAM_MSG, null);
		}
		if(StringUtils.isEmpty(nickname) || StringUtils.isEmpty(nickname.trim())) {
			nickname = null;
		} else {
			nickname = nickname.trim();
			if(nickname.length()>50) {
				return new ResultModel<String>(ResultModel.ERR_PARAM + "_2", "昵称过长", null);
			}
			boolean isExistUname = userService.isExistUname(nickname,uid);
			if(isExistUname) {
				return new ResultModel<String>(ResultModel.ERR_PARAM + "_3", "昵称已被占用", null);
			}
		}
		
		String logId = IdGenerator.getGuid();
		try {
			LogRestfulEntity entity =  new LogRestfulEntity();
			entity.setLogId(logId);
			entity.setApiPath("/updateUserBasicInfo");
			String content = request.getParameter("body");
			entity.setContent(content);
			entity.setUsedBy("huodui");
			if(logRestfulService.addEntity(entity)==1) {
				asyncService.asyncUpdateUserBasicInfo(uid.trim(),avatarUrl,nickname,sex);
				return new ResultModel<String>(ResultModel.SUCCESS, "操作成功", null);
			}else {
				return new ResultModel<String>(ResultModel.ERR_SYS, "操作失败", null);
			}
		} catch (Exception e) {
			return new ResultModel<String>(ResultModel.ERR_SYS, ResultModel.ERR_SYS_MSG, null);
		}
	}
	
	/**
	 * 	根据权限点&删除标志	查询用户uid列表
	 * @param resId
	 * @return
	 */
	@RequestMapping(value = "getUidsByResId", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getUidsByResId (String resId) {
		if(StringUtils.isEmpty(resId)) {
			logger.warn("根据resId获取用户uids失败,resId参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "调用失败,参数为空", null);
		}
		return userService.getUidsByResIdAndDr(resId, Constant.ONE);
	}
	
	/**
	 *  目前运动梦想课专用  asid 就这个认证存在
	 * @param uid  
	 * @param rleId	角色Id
	 * @return 用户真实姓名：realName  用户头像 avatarUrl 认证学校id asid 学校名称 sname 用户认证状态:
	 */
	@RequestMapping(value = "getUserVerifyInfo", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getUserVerifyInfo (String uid,String rleId) {
		if(StringUtils.isEmpty(uid) || StringUtils.isEmpty(rleId)) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, "调用失败,参数为空", null);
		}
		Map<String,String> rlt = verifyService.queryVerifyInfoByUidAndRleId(uid,rleId);
		if(rlt == null) {
			return new ResultModel<String>(ResultModel.NOT_FOUND_OBJECT, ResultModel.NOT_FOUND_OBJECT_MSG, null);
		}
		rlt.put("avatarUrl", headimgurlPrefix + uid);
		return new ResultModel<Map<String,String>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, rlt);
	}
	
	/**
	 * 同步学校基本信息
	 * @return
	 */
	@RequestMapping(value = "synSchoolBasicInfo", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<String> synSchoolBasicInfo() {
		try {
			return schoolBasicInfoService.synSchoolBasicInfo();
		} catch (ADreamServiceException e) {
			logger.warn("同步学校基本信息失败,{}", e.getMessage());
			return new ResultModel<String>(ResultModel.ERR_PARAM, "同步学校基本信息失败", null);
		}
	}
	/**
	 *  	验证运动梦想课认证 是否完善 (验证job和subject是否填写)
	 *  	运动梦想课专用
	 * 		@return
	 */
	@RequestMapping(value = "valiSportClassAuth", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<Boolean> valiSportClassAuth(String uid) {
		boolean flag = verifyService.valiSportClassAuth(uid);
		return new ResultModel<Boolean>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, flag);
	}
	
	/**
	 * 发布新版盒子动态
	 * @param body
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "publishDream2020Feed", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> publishDream2020Feed(String body, HttpServletRequest request) {
		if(StringUtils.isEmpty(body)) {
			logger.warn("发布新版盒子动态失败,body参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "发布新版盒子动态失败,参数为空", null);
		}
		String casid = UserUtil.getUidByRequest(request);
		if(StringUtils.isEmpty(casid)) {
			logger.warn("获取失败,casid为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "登录失效,请重新登录", null);
		}
		JSONObject data = JSONObject.parseObject(body);
		if(!data.containsKey("feedContent") || StringUtils.isEmpty(data.getString("feedContent"))) {
			logger.warn("发布新版盒子动态失败,feedContent参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "发布新版盒子动态失败,动态内容为空", null);
		}
		Dream2020FeedEntity dream2020Feed = new Dream2020FeedEntity();
		dream2020Feed.setCasid(casid);
		//考虑是否需要敏感词过滤
		dream2020Feed.setFeedContent(data.getString("feedContent"));
		dream2020Feed.setFeedFrom((!data.containsKey("feedFrom") || data.getIntValue("feedFrom") == 0) ? Constant.ONE : data.getIntValue("feedFrom"));
		dream2020Feed.setFeedClientId(Utils.getClientIpAddress(request));
		//审核状态设为'已审核'
		dream2020Feed.setAuditStatus(Constant.ONE);
		dream2020Feed.setCreatedAt(new Date());
		dream2020Feed.setUpdatedAt(new Date());
		return dream2020FeedService.addDream2020Feed(dream2020Feed);
	}
	
	/**
	 * 根据用户UID获取联系信息
	 */
	@RequestMapping(value="queryContactInfByUid",produces = "application/json;charset=UTF-8")
	@ResponseBody	
	public  ResultModel<?> queryContactInfByUid(String uid,String openid,HttpServletRequest request) {
		return userService.getContactInfByUid(uid,openid);
	}
}